// MARK: - Class
class Person {
    var id: String
    var name: String
    
    required init(id: String, name: String) {
        self.id = id
        self.name = name
    }
    
    convenience init(person: Person) {
        self.init(id: person.id, name: person.name)
    }
}

class Student: Person {
    var sID: String
    init(id: String, name: String, sID: String) {
        self.sID = sID
        super.init(id: id, name: sID)
    }
    
    required init(id: String, name: String) {
        self.sID = ""
        super.init(id: id, name: name)
    }
}


// MARK: - Struct
struct Sports: OptionSet {
    let rawValue: Int
    
    static let running = Sports(rawValue: 1 << 0)
    static let cycling = Sports(rawValue: 1 << 1)
    static let swimming = Sports(rawValue: 1 << 2)
    static let fencing = Sports(rawValue: 1 << 3)
    static let shooting = Sports(rawValue: 1 << 4)
    static let horseJumping = Sports(rawValue: 1 << 5)
}
let triathlon: Sports = [.swimming, .cycling, .running]
triathlon.contains(.swimming)
let modernPentathlon: Sports =
    [.swimming, .fencing, .horseJumping, .shooting, .running]
let commonEvents = triathlon.intersection(modernPentathlon)
commonEvents.contains(.swimming)
// swift中的[.bottomRight, .bottomLeft]就类似OC中.bottomRight | .bottomLeft

// MARK: - Enum
enum Icon: String {
    case music
    case sports
    case weather
    var filename: String {
        return "\(rawValue).png"
    }
}
//print(Icon.weather.filename)

enum Response {
    case success(items: [Int])
    case error(message: String)
}

func request() -> Response {
    var response: Response
    let i = Int.random(in: 0...10)
    if i % 2 == 0 {
        response = .success(items: [i, 1, 2, 3])
    } else {
        response = .error(message: "error")
    }
    
    return response
}
//switch request() {
//case .success(let items):
//    print(items)
//case .error(let message):
//    print(message)
//}

// Optional的原理
var age: Int?
//age = 17
//age = nil
//switch age {
//case .none:
//    print("none")
//case .some(let value):
//    print(value)
//}
